import { localStore } from 'vendor/utils/T'

export interface LoginUserInfo{
    accountId: string;
    userId: number;
    deptId: number;
    userName: string;
    nickName: string;
    avatar: string;
    roleType: string;
    lat: number;
    lng: number;
    deptType: string;
    permissions: string[],
    email: string,
    phonenumber: string,
    admin: boolean;
    account: {      // 账户信息
        accountId: string,
        remark: string,
        accountName: string,
        address: string,
        linkman: string,
        phone: string,
        industry: string,
        status: string
    }
}

export default class LoginUser {
    private storeKey = "sea_app_login_user_info"

    set = (info: any) => {
        localStore.set(this.storeKey, info)
    }

    get = ():LoginUserInfo => {
        const info = localStore.get(this.storeKey)

        return info || defaultLoginUserInfo;
    }

    clear = () => {
        localStore.remove(this.storeKey)
    }
}

const defaultLoginUserInfo: LoginUserInfo = {
    accountId: "",
    userId: 0,
    deptId: -1,
    userName: "",
    nickName: "",
    avatar: "",
    roleType: "",
    lat: 0,
    lng: 0,
    deptType: "",
    email: "",
    phonenumber: "",
    permissions: [],
    admin: false,
    account: {
        accountId: "",
        remark: "",
        accountName: "",
        address: "",
        linkman: "",
        phone: "",
        industry: "",
        status: "1"
    }
}
